package com.admin.service;

import com.admin.bean.PayApp;
import com.admin.dbdao.PayAppAdminDao;
import com.data.util.CheckDataUtils;
import com.data.util.DatabaseIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 付费推广
 *
 * @author:HingLo
 * @create 2017-09-27 12:50
 **/
@Service
public class PayAppAdminService {
    @Autowired
    private PayAppAdminDao payAppAdminDao;


    public List<?> findAllPayAppAdminService() {
        return payAppAdminDao.findAllPayAppAdminDao();
    }


    /**
     * 添加软件的类型到表中
     *
     * @param payApp
     * @param stime
     * @param etime
     * @return
     */
    public boolean submitPayAppAdminService(PayApp payApp, String stime, String etime) {

        if (!CheckDataUtils.stringUtils(stime, etime)) {
            return false;
        }
        stime = stime.trim();
        etime = etime.trim();
        if (!CheckDataUtils.stringUtils(payApp.getId())) {
            payApp.setId(DatabaseIdUtils.getDataIdOne());
        }
//时间处理
        SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
        try {
            payApp.setStarttime(format.parse(stime));
            payApp.setEndtime(format.parse(etime));
        } catch (ParseException e) {
            e.printStackTrace();
            payApp.setStarttime(new Date());
            payApp.setEndtime(new Date());
        }


        //添加到数据库中
        return payAppAdminDao.saveMassageDao(payApp);
    }

    /**
     * 删除信息
     *
     * @param id
     * @return
     */
    public boolean delpayAppAdminService(String id) {
        id = id.trim();
        return payAppAdminDao.deletePayAppAdminDao(id);
    }
}
